package cn.fuxi2022.rabbitmq.appletsPay.config;

import cn.fuxi2022.rabbitmq.appletsPay.constants.RegisterConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 签到的MQ配置
 */
@Configuration
public class RegisterRabbitMQconfig {

    /**
     * 签到交换机
     */
    @Bean
    public FanoutExchange registerExchange() {
        // 持久化打开+自动删除关闭
        return new FanoutExchange(RegisterConstants.GROUP_REGISTER_TTL_EXCHANGE, true, false);
    }

    /**
     * 签到交换机 的 签到队列
     */
    @Bean
    public Queue registerQueue() {
        // 打开队列持久化 + 排他队列 + 自动删除关闭
        return new Queue(RegisterConstants.GROUP_REGISTER_TTL_REGISTER_QUEUE, true, false, false);
    }

    /**
     * 签到队列 绑定 签到交换机
     */
    @Bean
    public Binding registerToExchange() {
        return BindingBuilder.bind(registerQueue()).to(registerExchange());
    }
}
